package com.ruoyi.market.service.impl;

import java.util.List;
import java.util.Map;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.market.constant.RedisKeyConstent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.db.mapper.ApplicationInfoMapper;
import com.ruoyi.db.domain.ApplicationInfo;
import com.ruoyi.market.service.IApplicationInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 包信息管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-11-14
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class ApplicationInfoServiceImpl implements IApplicationInfoService 
{
    @Autowired
    private ApplicationInfoMapper applicationInfoMapper;

    /**
     * 查询包信息管理
     * 
     * @param id 包信息管理主键
     * @return 包信息管理
     */
    @Override
    public ApplicationInfo selectApplicationInfoById(Long id)
    {
        return applicationInfoMapper.selectApplicationInfoById(id);
    }

    /**
     * 查询包信息管理列表
     * 
     * @param applicationInfo 包信息管理
     * @return 包信息管理
     */
    @Override
    public List<ApplicationInfo> selectApplicationInfoList(ApplicationInfo applicationInfo)
    {
        return applicationInfoMapper.selectApplicationInfoList(applicationInfo);
    }

    /**
     * 查询包信息管理列表
     *
     * @param applicationInfo 包信息管理
     * @return 包信息管理
     */
    @Override
    public List<Map<String, Object>> selectApplicationInfoListMap(ApplicationInfo applicationInfo)
    {
        return applicationInfoMapper.selectApplicationInfoListMap(applicationInfo);
    }

    /**
     * 新增包信息管理
     * 
     * @param applicationInfo 包信息管理
     * @return 结果
     */
    @Override
    public int insertApplicationInfo(ApplicationInfo applicationInfo)
    {
        applicationInfo.setCreateTime(DateUtils.getNowDate());
        return applicationInfoMapper.insertApplicationInfo(applicationInfo);
    }

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /**
     * 修改包信息管理
     * 
     * @param applicationInfo 包信息管理
     * @return 结果
     */
    @Override
    public int updateApplicationInfo(ApplicationInfo applicationInfo)
    {

        String redisKey = StrUtil.format(RedisKeyConstent.APPINFO_APPTYPE_KEY, applicationInfo.getAppType());
        stringRedisTemplate.delete(redisKey);

        applicationInfo.setUpdateTime(DateUtils.getNowDate());
        return applicationInfoMapper.updateApplicationInfo(applicationInfo);
    }

    /**
     * 批量删除包信息管理
     * 
     * @param ids 需要删除的包信息管理主键
     * @return 结果
     */
    @Override
    public int deleteApplicationInfoByIds(String ids)
    {
        return applicationInfoMapper.deleteApplicationInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除包信息管理信息
     * 
     * @param id 包信息管理主键
     * @return 结果
     */
    @Override
    public int deleteApplicationInfoById(Long id)
    {
        return applicationInfoMapper.deleteApplicationInfoById(id);
    }

    @Override
    public List<Map<String, Object>> selectAppChannelInfoMap(String appType) {
        return applicationInfoMapper.selectAppChannelInfoMap(appType);
    }

    @Override
    public List<Map<String, Object>> getAppTypeList() {
        return applicationInfoMapper.getAppTypeList();
    }
}
